<?php
declare(strict_types=1);

namespace app\admin\validate;

use think\Validate;

class Common extends Validate
{
    // 验证规则
    protected $rule = [
        'id'       => 'require',
        'username' => 'require|max:20',
        'password' => 'require|min:6|max:80',
        'password_confirm'  => 'require|confirm:password',
        'phone'    => 'require|mobile',
        'email'    => 'require|email',
        'role'     => 'require',
        'avatar'   => 'max:500',
        'page'     => 'number',
        'limit'    => 'number|between:0,100',
    ];

    // 错误提示
    protected $message = [
        'id.require'       => 'ID不能为空',
        'username.require' => '用户名必须填写',
        'username.max'     => '用户名最多20个字符',
        'password.require' => '密码必须填写',
        'password.min'     => '密码不少于6个字符',
        'password.max'     => '密码不超过80个字符',
        'password_confirm.require' => '请确认密码',
        'password_confirm.confirm' => '两次密码不一致',
        'phone.require'    => '手机号必须填写',
        'phone.mobile'     => '请输入正确手机号',
        'email.require'    => '邮箱必须填写',
        'email.email'      => '请输入正确邮箱',
        'role.require'     => '请选择角色',
        'avatar.max'       => '头像路径长度不能超过500个字符',
        'page.require'     => '页码不能为空',
        'limit.between'    => '条数只能在1-100之间',
    ];

    // 验证场景
    protected $scene = [
        'login'  => ['username', 'password'],
        'list'   => ['page', 'limit'],
        'delete' => ['id'],
        'add'    => ['username', 'password', 'email', 'phone', 'role', 'status', 'avatar'],
        'edit'   => ['id', 'username', 'email', 'phone', 'status', 'avatar'],
        'register' => ['username', 'password', 'password_confirm', 'email', 'phone', 'avatar'],
    ];
}